//
//  AppDelegate.m
//  Socket
//
//  Created by Viking Lai on 2018/5/25.
//  Copyright © 2018年 Viking Lai. All rights reserved.
//

#import "AppDelegate.h"
#import "SocketClientManager.h"
@interface AppDelegate ()
{
    SocketClientManager *sockClieManager;
}
@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    sockClieManager = [[SocketClientManager alloc]init];

}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}

- (IBAction)startBtn:(NSButton *)sender {

    [NSThread detachNewThreadSelector:@selector(translation:) toTarget:self withObject:nil];
}

- (void)translation:(float)volt{

    volt = 500;
    int idNum = volt/10;
    float afterVolt = (volt/2+48)/2;
    NSString *getOffset = [NSString stringWithFormat:@"[]eeprom read(mt_eload_0,cat08,%d,1)\r\n",idNum];
    
    NSString *offsetString = [sockClieManager getData:getOffset endStr:@"DONE"];
    
    NSString *strRanStart = @"[]ACK(";
    NSRange range = [offsetString rangeOfString:strRanStart];
    NSString *offset = [offsetString substringFromIndex:range.location+range.length];

    NSString *strRanEnd = @";DONE";
    range = [offset rangeOfString:strRanEnd];
    NSString *offsetTwo = [offset substringToIndex:range.location];
    
    float afterVoltTwo = afterVolt + [offsetTwo floatValue];
    
     NSLog(@"afterVoltTwo:%f\n",afterVoltTwo);
}

- (void)excuteAll
{
    
    NSString *string = [sockClieManager getData:@"Execute2400(':READ?')\r\n" endStr:@"\n"];
    NSLog(@"string:%@\n",string);
    
}

@end
